home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 08 - 1992 / 08.07 Nov⁄Dec 92 / Programmers' Challenge / count-paths.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-04  |  1.8 KB  |  73 lines  |  [TEXT/KAHL]

  1. /*
  2.  * count-paths.h:  Declarations for count-paths.c
  3.  *
  4.  *    Copyright (C) 1992,  William F. Galway
  5.  *
  6.  *    Anyone can do what they like with this code, as long as they
  7.  *    acknowledge its author, and include this message in their code.
  8.  */
  9.  
  10. typedef int BOOL;
  11.  
  12. #define TRUE 1
  13. #define FALSE 0
  14.  
  15. /* Possible target systems/compilers...  */
  16. #define ThinkC 0
  17. #define GnUnix 1
  18.  
  19. #if !defined(TARGET)
  20. #define TARGET ThinkC
  21. #endif
  22.  
  23. #if !defined(DEBUG)
  24. #define DEBUG FALSE
  25. #endif
  26.  
  27. #if !defined(VERBOSE)
  28. #define VERBOSE FALSE
  29. #endif
  30.  
  31. /* Maximum allowable dimensions of the "matrix".  */
  32. #define MAXORDER 10
  33.  
  34. #if (TARGET==GnUnix)
  35. /* This is the "Mac" StringPtr type.  The first byte gives the length, */
  36. /* the rest of the bytes make up the string.  */
  37. typedef unsigned char Str255[256], *StringPtr;
  38.  
  39. /* Native is the type most naturally addressed, roughly speaking...  */
  40. typedef void Native;
  41. #endif
  42.  
  43. #if (TARGET==ThinkC)
  44. /* Native is the type most naturally addressed, roughly speaking...  */
  45. typedef char Native;
  46. #endif
  47.  
  48. typedef struct locnode {
  49.     /* Next node in list for a given character.  */
  50.     struct locnode *next;
  51. } LocNode;
  52.  
  53. typedef struct {
  54.     /* Number of entries per row...  */
  55.     long dy;
  56.     /* Vector of LocNodes indexed by character code, giving first location */
  57.     /* of character.  */
  58.     LocNode char_index[256];
  59.     /* "Matrix" of LocNodes giving further locations of each character.  */
  60.     LocNode index_matrix[(2+MAXORDER)*(2+MAXORDER)];
  61. } Index;
  62.  
  63. /* BuildIndex builds up index for matrix of given order.  */
  64. void BuildIndex(long order, const char *matrix, Index *index);
  65.  
  66. /* count_paths counts paths using previously built index.  */
  67. long count_paths(const Index *index, const StringPtr word);
  68.  
  69. /* CountPaths is the "top level" path counting routine.  */
  70. long CountPaths(short order, char *matrix, const StringPtr inputWordPtr);
  71.  
  72.  
  73.